package iterator;

import java.util.Iterator;

public class SquaresIterator implements Iterator<Integer> {
    private final int max;
    private int current;
    private int ext;

    public SquaresIterator(int left, int right) {
        this.max = right;
        this.current = left;
    }

    @Override
    public boolean hasNext() {
        ext = current * current;
        return ext < max;
    }

    @Override
    public Integer next() {
        current++;
        return ext;
    }

    @Override
    public void remove() {
        throw new UnsupportedOperationException();
    }
}
